package kr.hkit.androidcomplete01.ch19;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public class BackWork extends Activity {

	TextView mResult;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		setContentView(R.layout.ch19_backwork);
		
		mResult = (TextView) findViewById(R.id.result);
		
	}
	
	public void mOnClick(View v){
		
		int start = 0, end = 100;
		int result;
		
		setProgressBarIndeterminateVisibility(true);
		result = Accumulate(start,end);
		mResult.setText(""+result);
		setProgressBarIndeterminateVisibility(false);
		
	}
	
	int Accumulate(int start, int end) {
		
		int sum = 0;
		for (int i=start; i<=end; i++) {
			sum += i;
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		return sum;
		
	}
}

